package com.common.sysinit;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.bean.SelectItem;
import com.common.GlobalPara;
import com.model.Syscode;

public class CacheSysCode {
	//需要使用线程同步来操作codelist
	public synchronized static void cacheSyscode(){
		GlobalPara._codelist = new LinkedHashMap<String, List<SelectItem>>();
		List<Syscode> codelist =  Syscode.dao.find("select * from syscode order by dmbh,sx");
		List<SelectItem> temp;
		Map<String,String> tempMap;
		for(Syscode code :codelist){
			temp = GlobalPara._codelist.get(code.getDmbh().toUpperCase());
			if(temp!=null){
				temp.add(new SelectItem(code.getCode(),code.getText()));
			}else{
				temp = new ArrayList<SelectItem>();
				temp.add(new SelectItem(code.getCode(),code.getText()));
				GlobalPara._codelist.put(code.getDmbh().toUpperCase(), temp);
			}
			
			tempMap= GlobalPara._codeMap.get(code.getDmbh().toUpperCase());
			if(tempMap!=null){
				tempMap.put(code.getCode(), code.getText());
			}else{
				tempMap = new HashMap<String, String>();
				tempMap.put(code.getCode(), code.getText());
				GlobalPara._codeMap.put(code.getDmbh().toUpperCase(), tempMap);
			}
		}
	}
}
